<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.model.Rate"%>
<%@ page import="com.control.RateControl"%>
<%@ page import="com.control.AdminControl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>为各寝室卫生情况打分</title>
	</head>
	<body>
		<%
			request.setCharacterEncoding("UTF-8");
			int admin_id = (Integer) session.getAttribute("user_id");
			AdminControl acontrol = new AdminControl();
			int building_id = acontrol.getAdmin(admin_id).getAdmin_building_id();
			String building_name = acontrol.getAdmin(admin_id).getAdmin_building_name();
			ArrayList<Rate> list = new ArrayList<Rate>();
			RateControl rcontrol = new RateControl();
			//获取时间
			Calendar date = Calendar.getInstance();
			//int day = date.get(Calendar.DAY_OF_MONTH);
			int month = date.get(Calendar.MONTH) + 1;
			int year = date.get(Calendar.YEAR);
			String start_time = "";
			String end_time = "";
			//System.out.println(month);
			start_time += year + "-" + month + "-1" ;
			if(month<12)
				end_time += year + "-" + (month+1) + "-1";
			else
				end_time += (year+1) + "-" + 1 + "-1";
			list = rcontrol.getUnRate(building_id, start_time, end_time);
			if(list.size()==0) {
		%>
				<script language="javascript">
					alert("该月已经评完");
					window.location.href="Give_score_show.jsp"
				</script>
		<%	}
			for(int i=0; i<10&&i<list.size(); i++) {
				Rate rate = list.get(i);
				String name = rate.getDorm_name();
				String comment = "comment" + name;
				
				if(request.getParameter(name)==null) 
					break;
					
				String score = request.getParameter(name);
				String des = request.getParameter(comment);
				Rate newRate = new Rate();
				newRate.setAdmin_id(admin_id);
				newRate.setRate_score(score);
				newRate.setRate_des(des);
				newRate.setDorm_id(rate.getDorm_id());
				rcontrol.insertRate(newRate);
			}
		%>
		<table width="98%" border="0" align="center">
			<tr>
				<td></td>
			</tr>
			<tr>
				<td></td>
			</tr>
			<tr>
				<td>
					<fieldset>
						<legend>
							评价各寝室的卫生情况
						</legend>
						<form action="Give_score.jsp" name="form1" method="post">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr height="10">
									<td></td>
								</tr>
								<tr align="center">
									<td align="center">
										我所管理的寝室楼: <%=building_name%>
									</td>
								</tr>
							</table>
							<table width="60%" border="0" align="center" cellspacing="0"
								cellpadding="0">
								<tr>
									<td height="20"></td>
								</tr>
								<tr>
									<td>
										<table border="1" width="99%" align="center" cellpadding="0"
											cellspacing="1" class="resultTable">
											<tr>
												<td width="2%" height="25" align="center" bgcolor="#D9F0FF">
													寝室
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
												           评等级
												</td>
												<td width="5%" height="25" align="center" bgcolor="#D9F0FF">
												          评语
												</td>
								</tr>
								<%
									list = rcontrol.getUnRate(building_id, start_time, end_time);
									if(list.size()==0) {
								%>
									<script language="javascript">
										alert("该月已经评完");
										window.location.href="Give_score_show.jsp"
									</script>
								<%}
									for(int i=0; i<10&&i<list.size(); i++) {
										Rate rate = list.get(i);
										String name = rate.getDorm_name();
										String comment = "comment" + name;
								%>
								 	<tr>
        								<td height="25" align="center"><%=name%></td>
 		 								<td height="25" align="center">
												优<input type="radio" name="<%=name %>" checked="checked" value="优"/>
												良<input type="radio" name="<%=name %>" value="良"/>
												中<input type="radio" name="<%=name %>" value="中"/>
												差<input type="radio" name="<%=name %>" value="差"/>
										</td>
										<td height="25" align="center"><input type="text" size="50" name="<%=comment %>" value=""/></td>
   									</tr>
   								<%}%>
							</table>
							
							</td>
							</tr>
							</table>
							<table align="center" style="margin-top: 10px">
							<tr>
							<td>
							<input type="submit" name="button1"  value="保存"/>
                             <input type="reset" name="button2"  value="重置"/>
							</td>
							</tr>
							</table> 
						</form>
					</fieldset>
				</td>
			</tr>
		</table>
	</body>
</html>
